package debux.apps.mltr.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import debux.apps.mltr.model.DatabaseController;

public class OpenActivity extends Activity {
    /** Called when the activity is first created. */
    ImageView openImage;
    AlphaAnimation anim;
    Handler handle = new Handler();
    boolean isAnimEnd = false;
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
        openImage = (ImageView)findViewById(R.id.imageView1);
        /* open database */
        
        openImage.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (!isAnimEnd){
					Intent intent = new Intent(OpenActivity.this,MainActivity.class);
					startActivity(intent);
					OpenActivity.this.finish();					
				}
			}
		});
    }
    
    @Override
    public void onResume(){
    	super.onResume();
    	DatabaseController.init(this.getApplicationContext());
        anim = new AlphaAnimation(0, 1);
        anim.setDuration(3000);
        anim.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(OpenActivity.this,MainActivity.class);
				startActivity(intent);
				isAnimEnd = true;				
				OpenActivity.this.finish();
			}
		});
        handle.post(new Runnable() {
			
			public void run() {
				// TODO Auto-generated method stub
				openImage.startAnimation(anim);	
			}
		});
    }
}